package main

import (
	"fmt"
	"sync"
	"time"
)

var rwLock sync.Mutex
var wg sync.WaitGroup

func read() {
	defer wg.Done()
	rwLock.Lock()
	fmt.Println("开始读取数据")
	time.Sleep(time.Second)
	fmt.Println("读取成功")
	rwLock.Unlock()
}
func write() {
	defer wg.Done()
	rwLock.Lock()
	fmt.Println("开始修改数据")
	time.Sleep(time.Second * 10)
	fmt.Println("修改成功")
	rwLock.Unlock()
}
func main() {
	wg.Add(4)
	for i := 0; i < 3; i++ {
		go read()
	}
	for j := 0; j < 1; j++ {
		go write()
	}
	wg.Wait()
}
